Part Number Hot Search : 
100LS N2907A MAX106 IXLD429Y MAX14532 14D220K ATP037SM 10A60
Product Description
Full Text Search
 

To Download AN669 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  m 1997 microchip technology inc. ds00669a-page 1 introduction with the advent of mplab-c, the microchip c-com- piler, many picmicro ? users need to embed existing assembly language routines and/or microchip applica- tion notes into c. this application note explains how to embed an assembly language program into mplab-c, version 1.10, and the issues therein. for example, embedding interrupt save and restore must be done using assembly language. also, critical timing routines may require assembly. the 32-bit ?ating point multiply routine from an575 is used to illustrate this process. the remaining 32-bit ?ating point math routines are embedded into individual c functions and are included in the ?e accompanying this application note. procedure for this example, we?l use a pic16c74a with 4k program memory, and 192 bytes of ram. embedding assembly routines in order to embed an assembly language routine in c code place the #asm and #endasm directives around the assembly routine. furthermore, if this is a subrou- tine, as is the case with the ?ating point multiply, then embed the assembly code within a c function declara- tion. the #asm construct is illustrated in example 1 with an excerpt from the 32-bit ?ating point routine. authors: rick evans microchip technology, inc. richard fischer example 1: #asm, #endasm construct void fpm32(void) { #asm fpm32 movf aexp,w ;test for zero btfss _z ;arguements movf bexp,w btfsc _z goto res032m m32bne0 movf aargb0,w xorwf bargb0,w movwf sign ;save sign movf bexp,w ;in sign addwf exp, f movlw expbias-1 ;...etc. #endasm } locating the routine in program memory, goto s and call s there are two 2k word pages of program memory in the pic16c74a. program memory 000h to 7ffh is page 0, 800h to fffh is page 1. by making fpm32() a c function, mplab-c initializes the appropriate page bit in the pclath register before the subroutine call is made. (see data sheet for more on pclath). a potential problem could arise, however, if the new c function, fpm32(), crosses the page boundary (7ffh,800h). mplab-c does not insert code into the assembly code to initialize the page bits (remember mplab-c does take care of paging for function calls). that means it is up to the programmer to either; 1) add assembly language to initialize pclath appropriately, or 2) move the entire #asm function within a single page. option 1 involves more work. the programmer must ?st compile the c code, then analyze the listing ?e to see if the assembly function crossed a page boundary. finally, add the appropriate assembly lan- guage to initialize pclath then re-compile. this solu- tion is not desirable since every time new c code is added to or deleted from the program, the routine, fpm32() can potentially move across the page bound- ary. option 2 is the simplest solution - to locate the c function in a single page. embedding assembly routines into c language using a floating point routine as an example AN669
1997 microchip technology inc. ds00669a -page 2 AN669 t o illustr ate , lets f orce fpm32() to cross the page boundar y . a pr agma directiv e is required to locate a routine (example 2). example 2: for cing fpm32 to cr oss the pa g e boundar y #pragma memory rom [maxrom-0x7f0] @ 0x7f0; #include "fpm32.inc" the listing le gener ated is sho wn in example 3 . notice the statement goto mtun32 at address 0x7fc . ho w- e v er , the routine mtun32 is located at address 0x801. remember , with the pic16c74a the goto instr uction only has an ele v en bit address r ange . with the goto mtun32 e xample , one more bit of address is needed to br anch to 0x801 from 0x7fc . the e xtr a bit of address is located in the pcla th register . that means assem- b ly code w ould ha v e to be inser ted into the oating point routines to initializ e pcla th bef ore each goto . since this solution is not desir ab le , the best approach is to locate the oating point subroutine in a single page . f or e xample , change the pragma directiv e in example 2 to locate the routine at 0x800. it is impor tant to note that when fpm32() is called as a c function, the page bit in pcla th is updated b y mplab-c . in other w ords mplab-c adds the neces- sar y assemb ly language code needed to call fpm32() or an y other c function. the c function is called cor- rectly , b ut once within the c function, the r a w embed- ded assemb ly language might ha v e goto s or call s that cross o v er the page boundar y and cause prob lems . example 3: fpm32 f or ced to ad dress 0 x 7f0 to sho w cr ossing fr om pa g e 0 to pa g e 1 void fpm32 (void) { #asm . . some code here . 07f0 0838 fpm32 movf aexp,w ;test for zero arguments 07f1 1d03 btfss _z 07f2 0839 movf bexp,w 07f3 1903 btfsc _z 07f4 284e goto res032m 07f5 0826 m32bne0 movf aargb0,w 07f6 0633 xorwf bargb0,w 07f7 00ae movwf sign ;save sign in sign 07f8 0839 movf bexp,w 07f9 07b8 addwf exp, f 07fa 307e movlw expbias-1 07fb 1c03 btfss _c 07fc 2801 goto mtun32 ;****** won? work ! 07fd 02b8 subwf exp,f 07fe 1803 btfsc _c 07ff 2843 goto setfov32m ;set multiply overflow flag 0800 2804 goto mok32 0801 02b8 mtun32 subwf exp,f ;****** in page 1 ! 0802 1c03 btfss _c 0803 2854 goto setfun32m . . some more code here . #endasm }
1997 microchip technology inc. ds00669a -page 3 AN669 assemb l y langua g e v ariab les, inc lude files, etc. f or the oating point math routines of an575, there is one include le which contains impor tant constant and register declar ations: math16.inc . this le of declar a- tions is r ather e xtensiv e , ho w e v er , it is str aightf orw ard to con v er t it to c . example 4 sho ws a segment of the math16.inc requir ing some attention f or the con v er- sion. example 4: math16.inc e xcerpt fr om an575. assemb l y langua g e file b0 equ 0 b1 equ 1 b2 equ 2 b3 equ 3 b4 equ 4 b5 equ 5 b6 equ 6 b7 equ 7 msb equ 7 lsb equ 0 . . etc. . aargb7 equ 0x20 aargb6 equ 0x21 aargb5 equ 0x22 aargb4 equ 0x23 aargb3 equ 0x24 aargb2 equ 0x25 aargb1 equ 0x26 aargb0 equ 0x27 aarg equ 0x27 ; most significant ; byte of argument a these constant and v ariab le dec larations need to be con ver ted to c langua g e dec larations example 5 sho ws the equiv alent c constant and v ar i- ab le declar ations . the equates in assemb ly language create constants . the equiv alent c language is a #define . moreo v er , v ar iab les are declared in assem- b ly language b y equating a v ar iab le name to a register ram location (i.e . aargb7 equ 0x20 ). in c the v ar i- ab les are declared b y assigning a type to the v ar iab le . in the listing in example 5 , aargb7 is declared as an unsigned integer data type . example 5: the con ver ted math16c.c file . c langua g e file #define b0 0 #define b1 1 #define b2 2 #define b3 3 #define b4 4 #define b5 5 #define b6 6 #define b7 7 #define msb 7 #define lsb 0 . . etc. . unsigned int aargb0 @ accb0; // most significant byte of argument a unsigned int aargb1 @ accb1; unsigned int aargb2 @ accb2; unsigned int aargb3 @ accb3; unsigned int aargb4 @ accb4; unsigned int aargb5 @ accb5; unsigned int aargb6 @ accb6; unsigned int aargb7 @ accb7; // least significant byte of argument a unsigned int aarg @ acc; // most significant byte of argument a
AN669 ds00669a -page 4 1997 microchip technology inc. using 32-bit floating p oint multipl y using the 32-bit oating point m ultiply supplied with an575 in a c prog r am is str aightf orw ard. first, cop y the entire routine from the le fpm32.a16 (from an575). then, create a function with the same name as the assemb ly routine . lets tak e a w ell kno wn f or m ula: let, p = 3.141592654 r = 12.34567898 meters find a: a p r 2 = w e need to con v er t the pre vious decimal n umbers to microchip 32-bit oating point. use fpm32 (from an575), to solv e the equation. w e will use mplab-c and use our c function named fpm32(). the main routine is listed in example 6. an575 comes with a handy utility called fprep.exe . this microchip le is a dos e x ecutab le . when r unning fprep , y ou can enter in a decimal n umber and it dis- pla ys the he xadecimal oating point n umber . t ab le 1 sho ws the n umbers in our e xample and their equiv alent oating point f or mats . t ab le 1: pic micr o ? 32-bit floating p oint representations of our e xample example 6: main r outine to test out our ne w 32-bit float multipl y in c #include "16c74a.h" #include "math16c.c" #include "fpm32.inc" // notice that fpm32 is located in page 0 // thus, all gotos reside in the same page. void main (void) { aexp = 0x80; // pi = 3.141592654 aargb0 = 0x49; aargb1 = 0x0f; aargb2 = 0xdb; bexp = 0x82; // r = 12.34567898 bargb0 = 0x45; bargb1 = 0x87; bargb2 = 0xe7; fpm32(); // aarg = pi * r // you must reload r into barg since // fpm32() destroys barg. bexp = 0x82; // r = 12.34567898 bargb0 = 0x45; bargb1 = 0x87; bargb2 = 0xe7; fpm32(); // aarg = (pi*r)*r while(1); } micr oc hip floating p oint equiv alent decimal number exp b0 (msb) b1 b2 (lsb) p = 3.141592654 0x80 0x49 0x0f 0xdb r = 12.34567898 meters 0x82 0x45 0x87 0xe7 a = 478.8283246 m 2 -- fprep .e x e calculated result 0x87 0x6f 0x6a 0x07 a = 478.8283246 m 2 -- pic16c74a measured result using mplab 3.12 and picmaster 16j probe 0x87 0x6f 0x6a 0x07
1997 microchip technology inc. ds00669a -page 5 AN669 summar y f or this discussion only the 32-bit oating point m ultiply is used. ho w e v er , the same pr inciples of embedded assemb ly language routines into c code can be used with other assemb ly language routines . a summar y list of a step- b y- step process to embed assemb ly code into y our c code is belo w: con v er t assemb ly register equ equates to c v ar i- ab le types such as unsigned int. con v er t constants to #define in c . place the assemb ly code into a subroutine using #asm and #endasm t o a v oid paging issues in par ts with m ultiple pro- g r am memor y pages , f orce the code to an address where it will not cross a page boundar y . f or e xample: #pragma memory rom [maxrom-0x800] @ 0x800; macros and conditional assemb ly will ha v e to be re wr itten in actual in-line assemb ly code . the mplab-c compiler does not suppor t these higher le v el assemb ly options to the same deg ree as the assemb ler , mp asm. f or y our con v enience , all the 32-bit oating point rou- tines in application note an575 are pro vided in a zip le along with this application note . each routine has been separ ated to w or k as a stand-alone routine . there is a separ ate le f or each oating point routine . the les ma y be included individually into y our c code . t ab le 2 sho ws a list of all the les and routines included with this application note . t ab le 2: 32-bit floating point c files/functions inc luded with this application note an575 original assemb l y routine/ le * equiv alent c le/function purpose - e xample .c the e xample main() routine calculating the area giv en the r adius . (uses fpm32) flo2432 o2432.inc 24-bit integer to 32-bit oating point con v ersion flo3232 o3232.inc 32-bit integer to 32-bit oating point con v ersion fpd32 fpd32.inc 32-bit oating point divide fpm32 fpm32.inc 32-bit oating point m ultiply fp a32 fps32 fpsa32.inc fps32() 32-bit subtr act fpa32() 32-bit add 32-bit oating point add 32-bit oating point subtr act int3224 int3224.inc 32-bit oating point to 24-bit integer con v ersion int3232 int3232.inc 32-bit oating point to 32-bit integer con v ersion nrm3232 nr m3232.inc 32-bit nor malization of unnor maliz ed 32-bit oating point n umbers nrm4032 nr m4032.inc 32-bit nor malization of unnor maliz ed 40-bit oating point n umbers math16.inc math16c.c v ar iab les and constants need f or the oating point functions * chec k microchip w eb site and b ulletin board f or latest code .
? 2002 microchip technology inc. information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. no representation or warranty is given and no liability is assumed by microchip technology incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. use of microchip?s products as critical com- ponents in life support systems is not authorized except with express written approval by microchip. no licenses are con- veyed, implicitly or otherwise, under any intellectual property rights. trademarks the microchip name and logo, the microchip logo, filterlab, k ee l oq , microid, mplab, pic, picmicro, picmaster, picstart, pro mate, seeval and the embedded control solutions company are registered trademarks of microchip tech- nology incorporated in the u.s.a. and other countries. dspic, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, microport, migratable memory, mpasm, mplib, mplink, mpsim, mxdev, picc, picdem, picdem.net, rfpic, select mode and total endurance are trademarks of microchip technology incorporated in the u.s.a. serialized quick turn programming (sqtp) is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2002, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. microchip received qs-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona in july 1999. the company?s quality system processes and procedures are qs-9000 compliant for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms and microperipheral products. in addition, microchip ? s quality system for the design and manufacture of development systems is iso 9001 certified. note the following details of the code protection feature on picmicro ? mcus.  the picmicro family meets the specifications contained in the microchip data sheet.  microchip believes that its family of picmicro microcontrollers is one of the most secure products of its kind on the market to day, when used in the intended manner and under normal conditions.  there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowl - edge, require using the picmicro microcontroller in a manner outside the operating specifications contained in the data sheet. the person doing so may be engaged in theft of intellectual property.  microchip is willing to work with the customer who is concerned about the integrity of their code.  neither microchip nor any other semiconductor manufacturer can guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ? unbreakable ? .  code protection is constantly evolving. we at microchip are committed to continuously improving the code protection features of our product. if you have any further questions about this matter, please contact the local sales office nearest to you.
? 2002 microchip technology inc. m americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: 480-792-7627 web address: http://www.microchip.com rocky mountain 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7966 fax: 480-792-7456 atlanta 500 sugar mill road, suite 200b atlanta, ga 30350 tel: 770-640-0034 fax: 770-640-0307 boston 2 lan drive, suite 120 westford, ma 01886 tel: 978-692-3848 fax: 978-692-3821 chicago 333 pierce road, suite 180 itasca, il 60143 tel: 630-285-0071 fax: 630-285-0075 dallas 4570 westgrove drive, suite 160 addison, tx 75001 tel: 972-818-7423 fax: 972-818-2924 detroit tri-atria office building 32255 northwestern highway, suite 190 farmington hills, mi 48334 tel: 248-538-2250 fax: 248-538-2260 kokomo 2767 s. albright road kokomo, indiana 46902 tel: 765-864-8360 fax: 765-864-8387 los angeles 18201 von karman, suite 1090 irvine, ca 92612 tel: 949-263-1888 fax: 949-263-1338 new york 150 motor parkway, suite 202 hauppauge, ny 11788 tel: 631-273-5305 fax: 631-273-5335 san jose microchip technology inc. 2107 north first street, suite 590 san jose, ca 95131 tel: 408-436-7950 fax: 408-436-7955 toronto 6285 northam drive, suite 108 mississauga, ontario l4v 1x5, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific australia microchip technology australia pty ltd suite 22, 41 rawson street epping 2121, nsw australia tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing microchip technology consulting (shanghai) co., ltd., beijing liaison office unit 915 bei hai wan tai bldg. no. 6 chaoyangmen beidajie beijing, 100027, no. china tel: 86-10-85282100 fax: 86-10-85282104 china - chengdu microchip technology consulting (shanghai) co., ltd., chengdu liaison office rm. 2401, 24th floor, ming xing financial tower no. 88 tidu street chengdu 610016, china tel: 86-28-6766200 fax: 86-28-6766599 china - fuzhou microchip technology consulting (shanghai) co., ltd., fuzhou liaison office unit 28f, world trade plaza no. 71 wusi road fuzhou 350001, china tel: 86-591-7503506 fax: 86-591-7503521 china - shanghai microchip technology consulting (shanghai) co., ltd. room 701, bldg. b far east international plaza no. 317 xian xia road shanghai, 200051 tel: 86-21-6275-5700 fax: 86-21-6275-5060 china - shenzhen microchip technology consulting (shanghai) co., ltd., shenzhen liaison office rm. 1315, 13/f, shenzhen kerry centre, renminnan lu shenzhen 518001, china tel: 86-755-2350361 fax: 86-755-2366086 hong kong microchip technology hongkong ltd. unit 901-6, tower 2, metroplaza 223 hing fong road kwai fong, n.t., hong kong tel: 852-2401-1200 fax: 852-2401-3431 india microchip technology inc. india liaison office divyasree chambers 1 floor, wing a (a3/a4) no. 11, o?shaugnessey road bangalore, 560 025, india tel: 91-80-2290061 fax: 91-80-2290062 japan microchip technology japan k.k. benex s-1 6f 3-18-20, shinyokohama kohoku-ku, yokohama-shi kanagawa, 222-0033, japan tel: 81-45-471- 6166 fax: 81-45-471-6122 korea microchip technology korea 168-1, youngbo bldg. 3 floor samsung-dong, kangnam-ku seoul, korea 135-882 tel: 82-2-554-7200 fax: 82-2-558-5934 singapore microchip technology singapore pte ltd. 200 middle road #07-02 prime centre singapore, 188980 tel: 65-334-8870 fax: 65-334-8850 taiwan microchip technology taiwan 11f-3, no. 207 tung hua north road taipei, 105, taiwan tel: 886-2-2717-7175 fax: 886-2-2545-0139 europe denmark microchip technology nordic aps regus business centre lautrup hoj 1-3 ballerup dk-2750 denmark tel: 45 4420 9895 fax: 45 4420 9910 france microchip technology sarl parc d?activite du moulin de massy 43 rue du saule trapu batiment a - ler etage 91300 massy, france tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany microchip technology gmbh gustav-heinemann ring 125 d-81739 munich, germany tel: 49-89-627-144 0 fax: 49-89-627-144-44 italy microchip technology srl centro direzionale colleoni palazzo taurus 1 v. le colleoni 1 20041 agrate brianza milan, italy tel: 39-039-65791-1 fax: 39-039-6899883 united kingdom arizona microchip technology ltd. 505 eskdale road winnersh triangle wokingham berkshire, england rg41 5tu tel: 44 118 921 5869 fax: 44-118 921-5820 01/18/02 w orldwide s ales and s ervice


▲Up To Search▲   

 
Price & Availability of AN669

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X